<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //reduce 方法，数组的求和方法
        let arr = [1,2,3,4,5,6,7,8,9]

        //语法一：有初始值
        // let res1 = arr.reduce((总和,数组元素) => {
        //     return 累加的式子
        // },'初始值')


        // let res1 = arr.reduce((sum,item) => {
        //     return sum += item
        // },100)    
        // console.log(res1)

        //语法二：没有初始值
        // let res2 = arr.reduce((总和,数组元素)  => {
        //     return 累加的式子
        // })

        // let res2 = arr.reduce((sum,item) => {
        //     return sum += item
        // })    
        // console.log(res2)

        //------实例
        let list = [
            {id:2,subject:'语文',score:80},
            {id:4,subject:'数学',score:90},
            {id:6,subject:'英语',score:30}
        ]
        let res = list.reduce((sum,item) => {
            return sum += item.score
        },0)
        console.log(res)
    </script>
</body>
</html>